#!perl
use Test::More tests => 53;
use lib 't';
use Wx::Perl::SimpleThread;

use WxTesting qw( app_from_wxtesting_frame );

my $app = app_from_wxtesting_frame( 'SimpleThreadTestingFrame' );
$app->MainLoop;

package SimpleThreadTestingFrame;
use strict;
use base qw(WxTesting::Frame);
use Test::More;
use Wx qw( wxTheApp );
use Time::HiRes qw( sleep );

sub new {
    my $class = shift;
    my $self = $class->SUPER::new( undef, -1, 'Testing Wx::Perl::SimpleThread ');
    #$self->Show(1);
    return $self;
}

sub RunTests {
  {
    require TestModule::HandlerSimple;
    my $handler = TestModule::HandlerSimple->new('TestModule::ThreadSimple');
    ok(defined($handler), 'defined handler returned');
    $handler->run_number(6);
    while( $handler->not_complete ) { wxTheApp->Yield; };
    
    my @stash = ();
    for (my $i = 0; $i < 10; $i++ ) {
	my $hler = TestModule::HandlerSimple->new('TestModule::ThreadSimple');
	ok(defined($hler), 'defined handler many returned');
	$hler->run_number($i);
	push(@stash, $hler);
	wxTheApp->Yield; sleep 0.10;
    }
    my $notcompleted = 1;
    while($notcompleted) {
	$notcompleted = 0;
	for my $href ( @stash ) {
		if( $href->not_complete ) {
			wxTheApp->Yield; sleep 0.10;
			$notcompleted = 1;
		};
	}
    }
    
    @stash = ();
    my $multi = TestModule::HandlerSimple->new('TestModule::ThreadSimple');
    for (my $i = 0; $i < 10; $i++ ) {
	$multi->run_number($i);
	while( $multi->not_complete ) { wxTheApp->Yield; sleep 0.10; };
    }
  }
  
}

1;

